<?php
// include "GenFunction.php";

?>
		
<?php
Class Gen_Pr_Gr
{
	var$Table;
	
	//поля
	var $id;
	var $pr_id;
	var $gr_id;
	
	var$array_pr_gr;
	
		function Gen_Pr_Gr($array_projs_id=array(),$array_grps_id=array())
	{
		if(empty($array_projs_id))$array_projs_id=array_int_noreapet_autoGen(50);
		if(empty($array_grps_id))$array_grps_id=array_int_noreapet_autoGen(20);
		
		$this->CreateTable();
		
		//$this->array_projs_id=array_int_noreapet_autoGen($num_projs);
		foreach($this->array_cut($array_grps_id) as $gr_id)
		{
			foreach($array_projs_id as $pr_id)
			{
				$this->id++;
				$this->pr_id=$pr_id;
				$this->gr_id=$gr_id;
				// $this->InsertData();
			}
			
		}
		echo $this->db_query.'<br><br>';
		
	}
	
		function Show_row()
		{
			echo$this->id.'	';
			echo$this->pr_id.'	';
			echo$this->gr_id.'	';
			echo '<br>';
		}
		
			
		function CreateTable()
		{
		//echo
			$this->db_query.="CREATE TABLE `pr_gr` (
  `id` int(11) NOT NULL auto_increment,
  `pr_id` int(11) NOT NULL,
  `gr_id` int(11) NOT NULL,
  PRIMARY KEY  (`id`),
  FOREIGN KEY (pr_id) REFERENCES projects(id)
           ON UPDATE CASCADE
           ON DELETE CASCADE,
		   FOREIGN KEY (gr_id) REFERENCES groups(id)
           ON UPDATE CASCADE
           ON DELETE CASCADE
) ENGINE=InnoDB CHARACTER SET=UTF8 COMMENT='матрица-соответствие между группами и проектами' AUTO_INCREMENT=1 ;
".'<br><br>';
		}
		
		
			function InsertData()
		{
			$id=$this->id;
			$pr_id=$this->pr_id;
			$gr_id=$this->gr_id;
			$this->db_query.="INSERT INTO `pr_gr` VALUES ($id, '$pr_id','$gr_id');"."<br>";
		}
		
		function array_cut($arr)
		{
			$res=array();
			$result_size=rand(1,count($arr));
			$rand_keys = array_int_noreapet_autoGen(round($result_size/2));//array_rand($arr, $result_size);
			foreach($rand_keys as $key)array_push($res,$arr[$key]);
			return $res;
		}
		
		
}


 // $g_p_g=new Gen_Pr_Gr();

 
?>